<template>
	<view class="ys">

		<view class="infobox">
			<view class="title">
				商品信息
			</view>
			<view class="goodsitem" v-for="(item,index) in goods" :key="index">
				<view class="item" v-if="item.goods_info">
					<image :src="item.goods_info.cover_path" mode=""></image>
					<view class="g-infobox">
						<view class="g-title">
							{{item.goods_name}}
						</view>
						<view class="g-price">
							<view class="pricebox">
								<text class="price">￥{{item.total_price}}</text>
							</view>
							<text>×{{item.total_num}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="infobox" v-if="orderinfo !=''">
			<view class="title">
				订单信息
				<text>{{info.status.text}}</text>
			</view>
			<view class="infoli">
				<text>订单编号</text>
				<view class="ordernum" @click="copy(orderinfo.order_no)">
					{{orderinfo.order_no}}
					<uni-icons type="compose" size="18"></uni-icons>
				</view>
			</view>
			<view class="infoli time">
				<text class="left">接单时间</text>
				<text class="left">{{orderinfo.create_time}}</text>
			</view>
			<view class="infoli time">
				<text class="left">确认时间</text>
				<text class="left">{{orderinfo.confirm_time || ''}}</text>
			</view>
			<view class="infoli time">
				<text class="left">完成时间</text>
				<text class="left">{{orderinfo.complete_time || ''}}</text>
			</view>
		</view>

		<view class="infobox" v-if="orderinfo.user">
			<view class="title">
				客户信息
			</view>
			<view class="infoli time">
				<text class="left">昵称</text>
				<text class="left">{{orderinfo.user.nickname}}</text>
			</view>
			<view class="infoli time">
				<text class="left">联系方式</text>
				<view class="ordernum" @click="callPhone(orderinfo.user.phone)">
					{{orderinfo.user.phone}}
					<uni-icons type="phone-filled" size="18"></uni-icons>
				</view>
			</view>
		</view>
		<view class="infobox" v-for="(item,index) in games" :key="index">
			<view class="title">
				角色信息
			</view>
			<view class="rolelist">
				<view class="infoli">
					<text class="left">角色名</text>
					<text class="left">{{item.role_name || ''}}</text>
				</view>
				<view class="infoli">
					<text class="left">大区</text>
					<text class="left">{{item.zone}}</text>
				</view>
				<view class="infoli">
					<text class="left">服务器</text>
					<text class="left">{{item.server}}</text>
				</view>
				<view class="infoli">
					<text class="left">天赋</text>
					<text class="right">{{item.talent}}</text>
				</view>
				<view class="infoli">
					<text class="left">职业</text>
					<text class="right">{{item.job}}</text>
				</view>
				<view class="infoli">
					<text class="left">阵营</text>
					<text class="right">{{item.camp}}</text>
				</view>
				<view class="infoli">
					<text class="left">装等</text>
					<text class="left">{{item.eq_level}}</text>
				</view>
				<view class="infoli">
					<text class="left">子账号</text>
					<text class="left">{{item.son_account}}</text>
				</view>
				<view class="infoli">
					<text class="left">备注</text>
					<view class="ordernum" @click="copy(item.remarks)">
						{{item.remarks}}
						<uni-icons type="compose" size="18"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="infobox">
			<view class="title">
				代练截图
			</view>
			<view class="imgslist">
				<view class="imgbox" v-for="(item,index) in info.images" :key="index">
					<image :src="item.path" mode="aspectFill" @click="seeImg(item.path,index)"></image>
				</view>
			</view>
		</view>
		<view class="footer">
			<text></text>
			<view class="right">
				<view class="total">
					实付款：<text>￥{{orderinfo.pay_amount || 0}}</text>
				</view>
				<button @tap="copyall">一键复制</button>
				<button @tap="submitInfo" v-if="info.confirm_btn" :loading="loading" :disabled="loading">确认完成</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		acceptDetail,
		acceptConfirm
	} from "@/api/shop.js"
	export default {
		data() {
			return {
				order_id: '',
				orderinfo: [],
				amount: 0,
				contact_name: '',
				contact: '',
				goods_info: [],
				pick_address: '',
				games: [],
				goods: [],
				info: [],
				loading: false
			}
		},
		onLoad(e) {
			this.order_id = e.id
			this.acceptDetail()
		},
		methods: {
			copyall() {
				let data = `订单编号：${this.orderinfo.order_no}\r\n`
				if (this.orderinfo.user) {
					data += `昵称：${this.orderinfo.user.nickname}\r\n`
					data += `联系方式：${this.orderinfo.user.phone}\r\n`
				}
				this.goods.forEach(item => {
					data += `代练内容：${item.goods_name}\r\n`
				})
				this.games.forEach(item => {
					data += `-----角色信息-----\r\n`
					data += `角色名：${item.role_name || ''}\r\n`
					data += `大区：${item.zone}\r\n`
					data += `服务器：${item.server}\r\n`
					data += `拾取天赋：${item.talent}\r\n`
					data += `职业：${item.job}\r\n`
					data += `阵营：${item.camp}\r\n`
					data += `装等：${item.eq_level}\r\n`
					data += `子账号：${item.son_account}\r\n`
					data += `备注：${item.remarks}\r\n`
				})
				uni.setClipboardData({
					data
				})
			},
			seeImg(url, i) {
				let urls = this.info.images.map(item => item.path)
				uni.previewImage({
					urls: urls,
					current: i
				})
			},
			callPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				})
			},
			toAddress() {
				uni.openLocation({
					latitude: Number(this.wei),
					longitude: Number(this.jing),
					address: this.ti_address,
					name: this.ti_address,
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					}
				})
			},
			toPage(url) {
				uni.navigateTo({
					url
				})
			},

			SFinfo() {
				uni.navigateTo({
					url: '/pages/master/info?do_uid=' + this.orderinfo.do_uid
				})
			},
			submitInfo() {
				var that = this
				uni.showModal({
					title: '温馨提示',
					content: '是否确认完成订单?',
					success(res) {
						if (res.confirm) {
							that.loading = true
							acceptConfirm({
								id: that.order_id
							}).then(data => {
								uni.$showMsg(data.msg)
								if (data.code == 0) {
									setTimeout(() => {
										uni.navigateBack()
									}, 500)
								} else {
									that.loading = false
								}
							})
						}
					}
				})
			},
			CancelOrder() {
				var that = this
				uni.showModal({
					title: '温馨提示',
					content: '是否取消订单？',
					success(res) {
						if (res.confirm) {
							CancelOrder({
								order_id: that.order_id
							}).then(data => {
								uni.showToast({
									title: data.msg,
									icon: "none"
								})
								if (data.code == 200) {
									setTimeout(() => {
										uni.navigateBack()
									}, 500)
								}
							})
						}
					}
				})
			},
			copy(data) {
				uni.setClipboardData({
					data
				})
			},

			acceptDetail() {
				acceptDetail({
					id: this.order_id
				}).then(res => {
					this.info = res.data.info
					this.orderinfo = res.data.order
					this.games = res.data.games
					this.goods = res.data.order.goods
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		min-height: calc(100vh - 44px);
		background: linear-gradient(180deg, #050B18, #f9f9f9, #f9f9f9);
		padding: 10px 0;
		padding-bottom: 70px;
		box-sizing: border-box;
		background-repeat-y: no-repeat;
		font-size: 14px;
	}

	.goodsitem {
		display: flex;
		flex-direction: column;

		.item {
			display: flex;
			align-items: center;
			padding: 10px;
			box-sizing: border-box;
			border-bottom: 1px solid #eee;

			image {
				width: 70px;
				height: 70px;
				margin-right: 30rpx;
			}

			.g-infobox {
				flex: 1;
				display: flex;
				justify-content: space-between;
				flex-direction: column;
				height: 65px;

				.g-price {
					display: flex;
					justify-content: space-between;
					font-size: 14px;
					color: #999;

					.pricebox {
						display: flex;
						align-items: flex-end;

						.price {
							color: #050B18;
							font-weight: bold;
						}

						.oldprice {
							font-size: 12px;
							margin-left: 8px;
							color: #999;
							text-decoration: line-through;
						}
					}

				}
			}
		}

		.item:last-child {
			border: 0;
		}
	}

	.footer {
		height: 55px;
		padding: 10px;
		position: fixed;
		left: 50%;
		transform: translate(-50%);
		bottom: 0;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;
		box-sizing: border-box;
		max-width: 500px;

		.total {
			color: #999;

			text {
				color: #f00;
				font-weight: bold;
			}
		}

		.canle {
			color: #999;
		}

		.right {
			display: flex;
			align-items: center;
			justify-content: space-between;

			button {
				background: linear-gradient(70deg, #050B18, #050B18d1, #050B18);
				color: #fff;
				width: 80px;
				padding-left: 0;
				padding-right: 0;
				font-size: 14px;
				margin: 0;
				margin-left: 10px;
			}
		}

	}

	.top {
		padding: 10px;
		font-size: 30upx;
		color: #000;
		background: #fff;
		border-radius: 5px;
		width: 96%;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;

		.tips {
			display: flex;
			flex-direction: column;

			.tips-msg {
				font-size: 14px;
				color: #999;
				margin-top: 5px;
			}
		}

		.kefu {
			display: flex;
			align-items: center;
			font-size: 12px;
			white-space: nowrap;

			button {
				background: transparent;
				font-size: 12px;
				border: unset;
				outline: 0;
				box-sizing: 0;
				padding: 0;
				padding-left: 5px;
			}

			text {
				margin-left: 3px;
			}
		}

	}

	.infobox {
		background-color: #fff;
		width: 96%;
		margin: 0 auto;
		border-radius: 5px;
		margin-top: 10px;
		padding: 10px 0;
		box-shadow: 0 0 5px #f3f3f3;

		.title {
			padding: 10px;
			padding-top: 0;
			font-weight: bold;
			font-size: 14px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			text {
				font-weight: normal;
				background: #050B18;
				color: #fff;
				border-radius: 3px;
				padding: 2px 5px;
				font-size: 12px;
			}
		}

		.imgslist {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
		}

		.imgbox {
			padding: 0 10px;

			image {
				width: 80px;
				height: 80px;
				border-radius: 3px;
			}
		}

		.infoli {
			display: flex;
			padding: 10px;
			box-sizing: border-box;
			justify-content: space-between;

			input {
				text-align: right;
				padding: 0 5px;
				border-bottom: 1px solid #eee;
				font-size: 14px;
			}

			.right {
				width: 60%;
				text-align: right;
			}

			.ordernum {
				display: flex;
				align-items: center;

				text {
					margin-left: 5px;
				}
			}

			.tiaddress {
				display: flex;
				align-items: center;
				justify-content: flex-end;
			}

			.sfitem {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				border: 1px solid #fff;
				padding: 5px;
				border-radius: 5px;

				.left {
					display: flex;
					align-items: center;
				}

				.right {
					color: #f00;
				}

				image {
					width: 40px;
					height: 40px;
					margin-right: 10px;
					border-radius: 5px;
				}
			}

			.active {
				border-color: #050B18;
			}

			textarea {
				width: 100%;
				border: 1px solid #eee;
				border-radius: 5px;
				padding: 5px;
				box-sizing: border-box;
				font-size: 14px;
			}
		}

		.time {
			text {
				white-space: nowrap;
			}
		}
	}

	.textareabox {
		flex-direction: column;
	}

	.showbox {
		textarea {
			min-height: 100px;
		}
	}
</style>